﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Dasaar.Interaction;


namespace Dasaar.Interaction.TellStick
{
    public class Device
    {
        #region Private
        private int deviceID;
        #endregion

        #region Contructor & Destructor

        public Device(int deviceId)
        {
            this.deviceID = deviceId;
        }

        #endregion

        #region Device Metadata

        public int DeviceID { get { return deviceID; } }
        public string Name { get { return TelldusCore.GetName(deviceID); } set { TelldusCore.SetName(deviceID, value); } }
        public string Model { get { return TelldusCore.GetModel(deviceID); ; } set { TelldusCore.SetModel(deviceID, value); } }
        public DeviceProtocol Protocol { get { return TelldusCore.GetProtocol(deviceID); } set { TelldusCore.SetProtocol(deviceID, value); } }
        public DeviceType DeviceType { get { return TelldusCore.GetDeviceType(deviceID); } }

        #endregion

        #region Device Method Metadata

        public DeviceMethods Methods { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.All); } }
        public bool SupportsOn { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.On).IsFlagSet(DeviceMethods.On); } }
        public bool SupportsOff { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Off).IsFlagSet(DeviceMethods.Off); } }
        public bool SupportsBell { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Bell).IsFlagSet(DeviceMethods.Bell); } }
        public bool SupportsToggle { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Toggle).IsFlagSet(DeviceMethods.Toggle); } }
        public bool SupportsDim { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Dim).IsFlagSet(DeviceMethods.Dim); } }
        public bool SupportsExecute { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Execute).IsFlagSet(DeviceMethods.Execute); } }
        public bool SupportsUp { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Up).IsFlagSet(DeviceMethods.Up); } }
        public bool SupportsDown { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Down).IsFlagSet(DeviceMethods.Down); } }
        public bool SupportsStop { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Stop).IsFlagSet(DeviceMethods.Stop); } }
        public bool SupportsLearn { get { return TelldusCore.GetDeviceMethods(deviceID, DeviceMethods.Learn).IsFlagSet(DeviceMethods.Learn); } }

        public DeviceMethods GetSupportedMethods(DeviceMethods method = DeviceMethods.All)
        {
            return TelldusCore.GetDeviceMethods(deviceID, method);
        }
        #endregion

        #region Device Control

        public void On()
        {
            TelldusCore.On(deviceID);
        }

        public void Off()
        {
            TelldusCore.Off(deviceID);
        }
        public void Bell()
        {
            TelldusCore.Bell(deviceID);
        }
        public void Toggle()
        {
            TelldusCore.Toggle(deviceID);
        }
        public void Dim(int level)
        {
            TelldusCore.Dim(deviceID, level);
        }
        public void Execute()
        {
            TelldusCore.Execute(deviceID);
        }
        public void Up()
        {
            TelldusCore.Execute(deviceID);
        }
        public void Down()
        {
            TelldusCore.Down(deviceID);
        }
        public void Stop()
        {
            TelldusCore.Stop(deviceID);
        }
        
        #endregion

    }
}
